#include "widget.h"
#include "ui_widget.h"
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include <QDebug>
#include <dirent.h>
#include <QSlider>
#include <stdlib.h>
#include <QListWidget>
#include <QFile>
#include <QMetaType>
#include <QLabel>
#include <QListWidgetItem>
#include <QSize>
#include <QPixmap>
#include <QPainter>
void *getTimerThreadFunc(void *arg);
void *readPipeMSG(void *arg);
void *showSongThread(void * arg);
Widget::Widget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Widget)
{
    ui->setupUi(this);
    srand((unsigned)time(NULL));
    index =0;
    flag_pause=false;
    condFlag=false;
    changeSongFlag=false;
    totalTime = 0;
    currentTime=0;
    muteFlag=0;
    playMode=0;
    speedMode = 1;
    rowLinkTime.clear();
    songMap.clear();
    //设置播放倍速空间
    ui->speedModeBtn->setText("1.0X");
    ui->speedModeBtn->setFont(QFont("Microsoft Yahei", 15));

    //初始化互斥锁
    pthread_mutex_init(&mutexFifo,NULL);
    //初始化条件变量
    pthread_cond_init(&condFifo,NULL);
    scanSong();
    //初始化 mplayer
    mplayerInit();
    //创建一个获取当前时间以及进度条的线程
    pthread_t getTimeTid;
    pthread_create(&getTimeTid, NULL, getTimerThreadFunc, (void*)this);
    pthread_detach(getTimeTid);

    //创建一个接受无名管道的信息的线程（只能有一个）
    pthread_t readPipeTid;
    pthread_create(&readPipeTid, NULL, readPipeMSG, (void*)this);
    pthread_detach(readPipeTid);

    //创建一个线程显示歌词
    pthread_t showSong;
    pthread_create(&showSong, NULL, showSongThread, (void*)this);
    pthread_detach(showSong);



    //滑动歌曲进度条信号处理
    connect(ui->currentSlider,SIGNAL(sliderMoved(int)), this, SLOT(sliderClikedSlot()));
    connect(ui->currentSlider,SIGNAL(sliderReleased()), this, SLOT(sliderReleasedSlot()));
    //滑动声音进度条信号处理
    connect(ui->sliderVoice,SIGNAL(sliderReleased()), this, SLOT(sliderVoiceReleasedSlot()));

    //歌单列表点击处理
    connect(ui->songListWidget,SIGNAL(itemClicked(QListWidgetItem *)), this, SLOT(songListSlot(QListWidgetItem *)));
    //歌词列表点击处理
    connect(ui->songShowListWidget,SIGNAL(itemClicked(QListWidgetItem *)), this, SLOT(songShowListSlot(QListWidgetItem *)));
    //按下btnNextSong
    connect(ui->btnNextSong,SIGNAL(clicked(bool)), this, SLOT(playNextSong()));
    //按下btnPlaySong
    connect(ui->btnPlaySong,SIGNAL(clicked(bool)), this, SLOT(playSong()));
    //按下btnPreSong
    connect(ui->btnPreSong,SIGNAL(clicked(bool)), this, SLOT(playPreSong()));
    //按下btnSetVoice
    connect(ui->btnSetVoice,SIGNAL(clicked(bool)), this, SLOT(setVoice()));
    //捕获当前播放信号
    connect(ui->playModeBtn,SIGNAL(clicked(bool)), this, SLOT(playModeChange()));
    //捕获当倍速放信号
    connect(ui->speedModeBtn,SIGNAL(clicked(bool)), this, SLOT(speedModeChange()));
    //捕获当前时间信号
    connect(this, SIGNAL(currentTimeSignal(int)), this, SLOT(setCurrentTimeLabel(int)));
    //捕获歌曲总时间
    connect(this, SIGNAL(totalTimeSignal(int)), this, SLOT(setTotalTimeLabel(int)));
    //捕获当前进度信号
    connect(this,SIGNAL(currentProgressSignal(int)), this, SLOT(setCurrentSlider(int)));
    //歌曲结束播放下一首信号
    connect(this,SIGNAL(changeSongByMode()), this, SLOT(changeSongByModeSlot()));

    vector<string>::iterator it=vectorSong.begin();
    setVoice();

}

Widget::~Widget()
{
    delete ui;
    pthread_mutex_destroy(&mutexFifo);
    pthread_cond_destroy(&condFifo);
}

void Widget::mplayerInit()
{
    //创建一个无名管道
    pipe(fd);
    //创建有名管道
    mkfifo("fifo_cmd", 0666);


    //创建子进程启动mplayer
    pidMplayer = fork();
    if(pidMplayer == 0)//子进程
    {

        //重定向标准输出
        dup2(fd[1], 1);
        //使用exec启动mplayer
        execlp("mplayer","mplayer", "-idle","-slave","-quiet",\
               "-input","file=fifo_cmd",NULL);
        _exit(-1);
    }
    else if(pidMplayer > 0)
    {
        //打开管道
        //以写的方式打开(阻塞到某进程 以读的方式打开)
        fifo_fd = open("fifo_cmd", O_WRONLY);
        if (fifo_fd < 0)
        {
            printf("file:%s, line:%d  ",__FILE__,__LINE__);
            perror("open");
            return;
        }

        flag_pause = false;
        char songBuf[128]="";
        int len = sprintf(songBuf,"loadfile ./song/%s\n", vectorSong[index].c_str());
        // 解析歌词
        dealSong(vectorSong[index],(vectorSong[index]).size());
        condFlag = true;
        pthread_mutex_lock(&mutexFifo);
        totalTime = 0;
        // 切歌标志为真
        this->changeSongFlag = true;
        write(this->fifo_fd,songBuf, len);
        usleep(SLEEP_TIME);
        condFlag = false;
        pthread_cond_broadcast(&condFifo);
        pthread_mutex_unlock(&mutexFifo);

        ui->songListWidget->setCurrentRow(index + 1);

    }
}

void Widget::scanSong()
{
    //1、得到目录句柄
    DIR *dir = opendir("./song");
    if(NULL == dir)
    {
        printf("file:%s, line:%d  ",__FILE__,__LINE__);
        perror("opendir");
        return;
    }

    //2、根据目录句柄扫描当前文件
    while(1)
    {
        struct dirent *dirent = readdir(dir);
        if(NULL == dirent)
            break;
        if(dirent->d_type == DT_REG)
        {
            if(strstr(dirent->d_name,".mp3") != NULL)
            {
                vectorSong.push_back(string(dirent->d_name));
                ui->songListWidget->addItem(QString(dirent->d_name));
            }

        }
    }

    //关闭目录句柄
    closedir(dir);
}

void Widget::closeEvent(QCloseEvent *)
{
    condFlag = true;
    pthread_mutex_lock(&mutexFifo);
    write(this->fifo_fd,"quit\n",strlen("quit\n"));
    usleep(SLEEP_TIME);
    condFlag = false;
    pthread_cond_broadcast(&condFifo);
    pthread_mutex_unlock(&mutexFifo);

}

void Widget::dealSong(string pathName,int pathNameLen)
{
    if(pathName.size() == 0)
    {
        printf("file:%s, line:%d  ",__FILE__,__LINE__);
        perror("pathName");
        return;
    }
    fontSize.setPointSize(20);
    ui->singNameLabel->setFont(fontSize);
    ui->singNameLabel->setAlignment(Qt::AlignVCenter|Qt::AlignHCenter);
    ui->singNameLabel->setText(QString(pathName.replace(pathNameLen-4,pathNameLen-1,"").c_str()));
    string filePathName = "./song/" + pathName + ".lrc";
    QFile file(filePathName.c_str());
    if(file.open(QIODevice::ReadOnly))
    {
        songMap.clear();
        vector<int> songTime;
        char song[128] = "";
        //        bool getSong =false;
        while (1)
        {
            char songBuf[128] = "";
            memset(song,0,128);
            int min = 0;
            int sec = 0;
            qint64 reaLen = file.readLine(songBuf,sizeof(songBuf)-1);
            if(reaLen<=0)
            {
                break;
            }
            if(songBuf[1]>='a' && songBuf[1]<'z')
                continue;
            if(songBuf[1]>='0' && songBuf[1]<'9')
            {
                sscanf(songBuf,"[%d:%d.%*d]%s",&min,&sec,song);
                song[0] = song[0]== '\n'?'\0':song[0];
                songTime.push_back(min*60+sec);
                if(strlen(song) != 0)
                {
                    unsigned int i=0;
                    for(i=0;i<songTime.size();i++)
                    {

                        songMap.insert(make_pair(songTime.at(i),song));
                    }
                    songTime.clear();
                }
            }
        }
        file.close();
    }
}

void Widget::sliderClikedSlot()
{
    condFlag = true;
}

void Widget::sliderReleasedSlot()
{

    char seekBuf[128]="";
    int len = sprintf(seekBuf,"seek %d 2\n", (totalTime * ui->currentSlider->value() /100));
    pthread_mutex_lock(&mutexFifo);
    write(this->fifo_fd,seekBuf, len);
    usleep(SLEEP_TIME);

    condFlag = false;
    pthread_cond_broadcast(&condFifo);
    pthread_mutex_unlock(&mutexFifo);

}

void Widget::sliderVoiceReleasedSlot()
{
    char volumeBuf[16]="";
    char currentVoiceBuf[8]="";
    int currentVoice = ui->sliderVoice->value();
    int len = sprintf(volumeBuf,"volume %d 1\n", currentVoice);
    sprintf(currentVoiceBuf,"%d", currentVoice);
    condFlag = true;
    pthread_mutex_lock(&mutexFifo);
    usleep(SLEEP_TIME);
    write(this->fifo_fd,volumeBuf, len);
    usleep(SLEEP_TIME);
    condFlag = false;
    pthread_cond_broadcast(&condFifo);
    pthread_mutex_unlock(&mutexFifo);
    ui->voiceLabel->setText(QString(currentVoiceBuf));
    ui->voiceLabel->setFont(QFont("Microsoft Yahei", 15));


}


void Widget::playSong()
{
    flag_pause = flag_pause == false?true:false;
    if(flag_pause == true)
    {
        ui->btnPlaySong->setIcon(QIcon(QString(":/pic_play/24gl-pause.png")));
    }
    else
    {
        ui->btnPlaySong->setIcon(QIcon(QString(":/pic_play/24gl-play.png")));
    }

    condFlag = true;
    pthread_mutex_lock(&mutexFifo);
    write(this->fifo_fd,"pause\n", 6);
    usleep(SLEEP_TIME);
    condFlag = false;
    pthread_cond_broadcast(&condFifo);
    pthread_mutex_unlock(&mutexFifo);

}

void Widget::playNextSong()
{

    flag_pause = false;
    ui->btnPlaySong->setIcon(QIcon(QString(":/pic_play/24gl-play.png")));
    index++;
    if((unsigned int)index == vectorSong.size())
        index=0;
    char changeSongBuf[128]="";
    int len = sprintf(changeSongBuf,"loadfile ./song/%s\n", vectorSong[index].c_str());

    // 解析歌词
    dealSong(vectorSong[index],(vectorSong[index]).size());
    condFlag = true;
    pthread_mutex_lock(&mutexFifo);
    totalTime = 0;
    // 切歌标志为真
    this->changeSongFlag = true;
    write(this->fifo_fd,changeSongBuf, len);
    usleep(SLEEP_TIME);
    condFlag = false;
    pthread_cond_broadcast(&condFifo);
    pthread_mutex_unlock(&mutexFifo);

    ui->songListWidget->setCurrentRow(index + 1);

}

void Widget::playPreSong()
{
    ui->btnPlaySong->setIcon(QIcon(QString(":/pic_play/24gl-play.png")));
    index--;
    if(index == -1)
        index=vectorSong.size() - 1;

    char changeSongBuf[128]="";
    int len = sprintf(changeSongBuf,"loadfile ./song/%s\n", vectorSong[index].c_str());
    flag_pause = false;
    ui->btnPlaySong->setIcon(QIcon(QString(":/pic_play/24gl-play.png")));
    // 解析歌词
    dealSong(vectorSong[index],(vectorSong[index]).size());
    condFlag = true;
    pthread_mutex_lock(&mutexFifo);
    totalTime = 0;
    // 切歌标志为真
    this->changeSongFlag = true;
    write(this->fifo_fd,changeSongBuf, len);
    usleep(SLEEP_TIME);
    condFlag = false;
    pthread_cond_broadcast(&condFifo);
    pthread_mutex_unlock(&mutexFifo);
    ui->songListWidget->setCurrentRow(index + 1);

}

void Widget::setVoice()
{
    if(muteFlag == 0)
    {
        ui->btnSetVoice->setIcon(QIcon(QString(":/pic/voiceOpen.png")));
    }
    else if(muteFlag == 1)
    {
        ui->btnSetVoice->setIcon(QIcon(QString(":/pic/voiceClose.png")));
    }
    char setMute[16]="";
    int len = sprintf(setMute,"mute %d\n", muteFlag);
    condFlag = true;
    pthread_mutex_lock(&mutexFifo);
    write(this->fifo_fd,setMute, len);
    usleep(SLEEP_TIME);
    condFlag = false;
    pthread_cond_broadcast(&condFifo);
    pthread_mutex_unlock(&mutexFifo);
    muteFlag = (muteFlag+1)%2;

}

void Widget::setCurrentTimeLabel(int time)
{
    currentTime = time;
    int m=0,s=0;
    m = time/60;
    s = time%60;
    char buf[32]="";
    sprintf(buf, "%02d:%02d",m,s);

    ui->currentTimeLabel->setText(QString(buf));
    ui->currentTimeLabel->setFont(QFont("Microsoft Yahei", 15));
}

void Widget::setTotalTimeLabel(int time)
{

    int m=0,s=0;
    m = time/60;
    s = time%60;
    char buf[32]="";
    sprintf(buf, "%02d:%02d",m,s);
    ui->tatalTimeLabel->setText(QString(buf));
    ui->tatalTimeLabel->setFont(QFont("Microsoft Yahei", 15));
}

void Widget::setCurrentSlider(int currentProgress)
{
    ui->currentSlider->setValue(currentProgress);
}

void Widget::songListSlot(QListWidgetItem *item)
{


    char changeSongBuf[128]="";
    int len = sprintf(changeSongBuf,"loadfile ./song/%s\n", item->text().toStdString().c_str());
    flag_pause = false;
    ui->btnPlaySong->setIcon(QIcon(QString(":/pic_play/24gl-play.png")));
    // 解析歌词
    dealSong(item->text().toStdString(),(item->text().toStdString()).size());
    condFlag = true;
    pthread_mutex_lock(&mutexFifo);
    totalTime = 0;
    // 切歌标志为真
    this->changeSongFlag = true;
    write(this->fifo_fd,changeSongBuf, len);
    usleep(SLEEP_TIME);
    condFlag = false;
    pthread_cond_broadcast(&condFifo);
    pthread_mutex_unlock(&mutexFifo);
    index = ui->songListWidget->currentRow()-1;


}

void Widget::songShowListSlot(QListWidgetItem *item)
{
    int row = ui->songShowListWidget->row(item) + 4;
    condFlag = true;
    char seekBuf[128]="";
    int len = sprintf(seekBuf,"seek %d 2\n", rowLinkTime[row]);
    pthread_mutex_lock(&mutexFifo);
    write(this->fifo_fd,seekBuf, len);
    usleep(SLEEP_TIME);

    condFlag = false;
    pthread_cond_broadcast(&condFifo);
    pthread_mutex_unlock(&mutexFifo);

}
//播放模式  0:列表循环 1:单曲循环 2:顺序播放  3:随机播放
void Widget::playModeChange()
{
    playMode = (playMode + 1)%4;
    if(playMode == 0)
    {
        ui->playModeBtn->setIcon(QIcon(QString(":/pic_play/列表循环.png")));
    }
    else if(playMode == 1)
    {
        ui->playModeBtn->setIcon(QIcon(QString(":/pic_play/单曲循环.png")));
    }
    else if(playMode == 2)
    {
        ui->playModeBtn->setIcon(QIcon(QString(":/pic_play/顺序播放.png")));
    }
    else if(playMode == 3)
    {
        ui->playModeBtn->setIcon(QIcon(QString(":/pic_play/随机播放.png")));
    }
}
//播放模式  0:列表循环 1:单曲循环 2:顺序播放  3:随机播放
void Widget::changeSongByModeSlot()
{
    if(playMode == 0)
    {
        index++;
    }
    else if(playMode == 1)
    {    }
    else if(playMode == 2)
    {
        index++;
        if((unsigned int)index == vectorSong.size())
            return;
    }
    else if(playMode == 3)
    {
        index = rand()%vectorSong.size();
    }
    if((unsigned int)index == vectorSong.size())
        index=0;
    char changeSongBuf[128]="";
    int len = sprintf(changeSongBuf,"loadfile ./song/%s\n", vectorSong[index].c_str());
    flag_pause = false;
    // 解析歌词
    dealSong(vectorSong[index],(vectorSong[index]).size());
    condFlag = true;
    pthread_mutex_lock(&mutexFifo);
    totalTime = 0;
    // 切歌标志为真
    this->changeSongFlag = true;
    write(this->fifo_fd,changeSongBuf, len);
    usleep(SLEEP_TIME);
    condFlag = false;
    pthread_cond_broadcast(&condFifo);
    pthread_mutex_unlock(&mutexFifo);
    ui->songListWidget->setCurrentRow(index + 1);
}

//倍速模式  0:1倍   1:1.5倍 2:2倍
void Widget::speedModeChange()
{
    speedMode = (speedMode +1)%3;
    char speedModeBuf[16]="";
    int len = 0;
    if(speedMode == 0)
    {
        len = sprintf(speedModeBuf,"speed_set 1\n");
        ui->speedModeBtn->setText("1.0X");

    }
    else if(speedMode == 1)
    {
        len = sprintf(speedModeBuf,"speed_set 1.5\n");
        ui->speedModeBtn->setText("1.5X");
    }
    else if(speedMode == 2)
    {
        len = sprintf(speedModeBuf,"speed_set 2\n");
        ui->speedModeBtn->setText("2.0X");
    }

    ui->speedModeBtn->setFont(QFont("Microsoft Yahei", 15));
    condFlag = true;
    pthread_mutex_lock(&mutexFifo);
    write(this->fifo_fd,speedModeBuf, len);
    usleep(SLEEP_TIME);
    condFlag = false;
    pthread_cond_broadcast(&condFifo);
    pthread_mutex_unlock(&mutexFifo);

}


void *getTimerThreadFunc(void *arg)
{
    Widget *pThread = (Widget *)arg;

    while(1)
    {
        if(pThread->flag_pause == true)
        {
            usleep(SLEEP_TIME);

            continue;
        }
        pThread->update();
        pthread_mutex_lock(&pThread->mutexFifo);
        while (true == pThread->condFlag)
        {
            pthread_cond_wait(&pThread->condFifo, &pThread->mutexFifo);
        }
        //发送获取的当前时间的命令
        write(pThread->fifo_fd,"get_time_pos\n", strlen("get_time_pos\n"));
        usleep(SLEEP_TIME);
        //发送获取当前歌曲进度的命令
        write(pThread->fifo_fd,"get_percent_pos\n", strlen("get_percent_pos\n"));
        usleep(SLEEP_TIME);
        if(pThread->totalTime == 0)
        {
            write(pThread->fifo_fd,"get_time_length\n", strlen("get_time_length\n"));
            usleep(SLEEP_TIME);
        }
        pthread_mutex_unlock(&pThread->mutexFifo);
    }
}

void *readPipeMSG(void *arg)
{
    Widget *pThread = (Widget *)arg;

    //不停的获取无名管道的数据
    while(1)
    {
        char buf[256]="";
        int ret = read(pThread->fd[0], buf,sizeof(buf));


        if(ret> 0)
        {
            //判断消息的类型
            if(strncmp(buf,"ANS_TIME_POSITION", strlen("ANS_TIME_POSITION"))==0)
            {
                int time=0;
                sscanf(buf,"ANS_TIME_POSITION=%d",&time);
                //给UI发送当前时间信号
                emit pThread->currentTimeSignal(time);
                if(( pThread->totalTime != 0) && (time - pThread->totalTime > -2))
                    emit pThread->changeSongByMode();
            }
            else if(strncmp(buf,"ANS_PERCENT_POSITION", strlen("ANS_PERCENT_POSITION"))==0)
            {
                int currentProgress=0;
                sscanf(buf,"ANS_PERCENT_POSITION=%d",&currentProgress);
                //给UI发送进度信号
                emit pThread->currentProgressSignal(currentProgress);
            }
            else if(strncmp(buf,"ANS_LENGTH", strlen("ANS_LENGTH"))==0)
            {
                sscanf(buf,"ANS_LENGTH=%d",&(pThread->totalTime));
                //给UI发送进度信号
                emit pThread->totalTimeSignal(pThread->totalTime);
            }
            else if(strncmp(buf,"Position", strlen("Position"))==0)
            {
                sscanf(buf,"Position= %*d %*c");

            }

        }
    }

}

void *showSongThread(void * arg)
{
    //解决报错
    qRegisterMetaType<QItemSelection>("QItemSelection");
    qRegisterMetaType<QVector<int>>("QVector<int>");
    Widget *widgetHandl = (Widget *)arg;
    QListWidgetItem *newItem = NULL;
    map<int,string>::const_iterator songMapIterator;
    // map<歌词对应时间,行号>  为了通过行号获取歌词对应的时间
    map<int,int> songCurrentTime;
    while(1)
    {
        widgetHandl->changeSongFlag= false;
        int endtime=0;
        if(widgetHandl->songMap.size() == 0)
        {
            usleep(SLEEP_TIME);
            continue;
        }
        else
        {
            // 删除list上原有数据
            while (widgetHandl->ui->songShowListWidget->count() > 0)
            {
                newItem = widgetHandl->ui->songShowListWidget->takeItem(0);
                delete newItem;
                newItem = NULL;
            }
            widgetHandl->ui->songShowListWidget->clear();
            // 删除songCurrentTime上原有数据
            songCurrentTime.clear();

            // 行号，将歌词的时间与行号对应
            int row = 0;
            for(row=0;row<8;row++)
            {
                newItem = new QListWidgetItem(QString("        "));
                newItem->setSizeHint(QSize(450, 40));

                widgetHandl->ui->songShowListWidget->addItem(newItem);
                songCurrentTime.insert(make_pair((0-row-1),row));
                row++;
            }
            for(songMapIterator=widgetHandl->songMap.begin();\
                songMapIterator!=widgetHandl->songMap.end();songMapIterator++)
            {
                //将歌词按顺序插入list
                newItem = new QListWidgetItem(QString((*songMapIterator).second.c_str()));
                newItem->setSizeHint(QSize(450, 40));
                newItem->setFont(widgetHandl->fontSize);
                newItem->setTextAlignment(Qt::AlignVCenter|Qt::AlignHCenter);
                widgetHandl->ui->songShowListWidget->addItem(newItem);
                songCurrentTime.insert(make_pair((*songMapIterator).first,row));
                widgetHandl->rowLinkTime.insert(make_pair(row,(*songMapIterator).first));
                row++;
            }
            songMapIterator--;
            endtime = (*songMapIterator).first;

            int i=0;
            for(i=0;i<10;i++)
            {
                newItem = new QListWidgetItem(QString(""));
                newItem->setSizeHint(QSize(450, 40));
                widgetHandl->ui->songShowListWidget->addItem(newItem);
                songCurrentTime.insert(make_pair((0-row-1),row));
                row++;
            }

            while (widgetHandl->changeSongFlag == false)
            {
                songMapIterator = widgetHandl->songMap.begin();
                songMapIterator = widgetHandl->songMap.find(widgetHandl->currentTime);

                if(songMapIterator != widgetHandl->songMap.end())
                {
                    int getRow = songCurrentTime[((*songMapIterator).first)] - 4;

                    widgetHandl->ui->songShowListWidget->setCurrentRow(getRow-1);

                    widgetHandl->ui->songShowListWidget->setCurrentRow(getRow+4);

                    widgetHandl->ui->songShowListWidget->setCurrentRow(getRow);

                }
                else if((widgetHandl->currentTime >= endtime) && (songMapIterator == widgetHandl->songMap.end()))
                {
                    songMapIterator--;
                    int getRow = songCurrentTime[((*songMapIterator).first)] - 4;

                    widgetHandl->ui->songShowListWidget->setCurrentRow(getRow-1);

                    widgetHandl->ui->songShowListWidget->setCurrentRow(getRow+4);

                    widgetHandl->ui->songShowListWidget->setCurrentRow(getRow);
                }
                usleep(SLEEP_TIME);
            }
        }
    }
}

void Widget::paintEvent(QPaintEvent *)
{

    QPainter painter(this);
    QPixmap pixmap;
    pixmap.load(":/pic/background.jpg");
    pixmap.scaled(1024, 600);
    painter.drawPixmap(0,0,1024,600,pixmap);


    pixmap.load(":/pic/song1.png");
    pixmap.scaled(250, 250);
    //旋转角度
    static int imageRotate = 0;
    //设定旋转中心点
    painter.translate(ui->albumPictures->x()+125,ui->albumPictures->y()+125);
    //旋转的角度
    painter.rotate(imageRotate);
    //恢复中心点
    painter.translate(-ui->albumPictures->x()-125,-ui->albumPictures->y()-125);
    //画图操作
    painter.drawPixmap(ui->albumPictures->x(),ui->albumPictures->y(),250,250, pixmap);
    imageRotate += 1;
}
